//
//  WBNetworkTooles.swift
//  swiftAFN
//
//  Created by KIMI on 16/9/21.
//  Copyright © 2016年 KIMI. All rights reserved.
//

import UIKit
import AFNetworking
//网络请求类型
enum requestType: Int{
    
    case GET
    case POST
    
}

class WBNetworkTooles: AFHTTPSessionManager {
    
    

   //全局访问点
    static let sharedTools :WBNetworkTooles = {
        
        let tools = WBNetworkTooles()
        tools.responseSerializer.acceptableContentTypes?.insert("text/html")
        
        return tools
    }()
    
    //封装网络请求
    func requert(type: requestType,urlStr: String,params: Any?, callBack:@escaping (Any?,Error?)->()){
        
        if type == .GET {
            
            get(urlStr, parameters: params, progress: nil, success: { (_, response) in
                
                callBack(response, nil)
                }, failure: { (_, error) in
                    callBack(nil,error)
            })
        }else {
            
            post(urlStr, parameters: params, progress: nil, success: { (_, response) in
                callBack(response, nil)
                }, failure: { (_, error) in
                    
                    callBack(nil,error)
            })
        }
    }
    
    
    
}
